package com.example.batchprocessing.controller;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;

public class JobController {
    @Autowired
    JobLauncher jobLauncher;
    @Autowired
    Job importJob;
    public JobParameters jobParameters;

    //定时执行
    @Scheduled(cron = "0 0 0 10 * ?")
    public void execute() throws Exception {
        jobParameters = new JobParametersBuilder().addLong("time",
                System.currentTimeMillis()).toJobParameters();
        jobLauncher.run(importJob, jobParameters);
    }
}
